#!/usr/bin/env python
# -*- coding: utf-8 -*-
#### Copyright (c) 2008 Clóvis Fabrício Costa - All rights reserved

import atexit
import os
import readline
import rlcompleter

class _TestDir(object):
    def __dir__(self):
        return ['some_value']
_t = _TestDir()

if 'some_value' not in dir(_t):
    # Monkeypatch rlcompleter for python 2.5 compatibility
    def _dir(obj):
        __doc__ = dir.__doc__
        try:
            return obj.__dir__()
        except (AttributeError, TypeError):
            return dir(obj)

    rlcompleter.dir = _dir
    del _dir
del _t, _TestDir

readline.parse_and_bind("tab: complete")
historyPath = os.path.expanduser("~/.pysh_history")

def save_history(historyPath=historyPath):
    import readline
    readline.write_history_file(historyPath)
atexit.register(save_history)

if os.path.exists(historyPath):
    readline.read_history_file(historyPath)

del os, atexit, readline, rlcompleter, save_history, historyPath
